package com.rpc.example.handler;

import com.rpc.example.core.ClientFuture;
import com.rpc.example.core.Protocol;
import com.rpc.example.core.RequestHolder;
import com.rpc.example.core.Response;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Elvis
 * @version 1.0, 2022/11/11
 */
@Slf4j
public class RpcClientHandler extends SimpleChannelInboundHandler<Protocol<Response>> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Protocol<Response> msg) throws Exception {
        log.info("--------rpc result handler-----------");
        ClientFuture<Response> remove = RequestHolder.FUTURE_MAP.remove(msg.getHeader().getRequestId());
        remove.getPromise().setSuccess(msg.getData());
    }
}
